package com.neo.springcloud.alibaba.controller;

import com.google.common.collect.Maps;
import com.neo.springcloud.entities.CommonResult;
import com.neo.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @ClassName: PaymentController
 * @Title: cloud2021
 * @Package: com.neo.springcloud.alibaba.controller
 * @Description:
 * @Author: Kisen
 * @Date: 2021/11/17 0:13
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    public static HashMap<Long, Payment> hashMap = Maps.newHashMap();

    static {
        hashMap.put(1L, new Payment(1L, "3lzwvpo7hu2ty5ab0idr4fmexgsck1"));
        hashMap.put(2L, new Payment(2L, "ptc6h3lfz284b0g7j9yrdowsaik5ue"));
        hashMap.put(3L, new Payment(3L, "7g1au46qbjzkw2shodptfnlve58309"));
    }

    @GetMapping(value = "/paymentSQL/{id}")
    public CommonResult<Payment> paymentSQL(@PathVariable("id") Long id) {
        Payment payment = hashMap.get(id);
        return new CommonResult(200, "from mysql, serverPort: " + serverPort, payment);
    }
}
